package com.zeta.eduservice.service.impl;

import com.zeta.eduservice.entity.EduAcademy;
import com.zeta.eduservice.entity.EduClasss;
import com.zeta.eduservice.entity.EduMajor;
import com.zeta.eduservice.entity.vo.AcademyVo;
import com.zeta.eduservice.entity.vo.ClasssVo;
import com.zeta.eduservice.entity.vo.MajorVo;
import com.zeta.eduservice.mapper.EduAcademyMapper;
import com.zeta.eduservice.service.EduAcademyService;
import com.zeta.eduservice.service.EduClasssService;
import com.zeta.eduservice.service.EduMajorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 学院 服务实现类
 * </p>
 *
 * @author zeta
 * @param <E>
 * @since 2020-08-17
 */
@Service
public class EduAcademyServiceImpl<E> extends ServiceImpl<EduAcademyMapper, EduAcademy> implements EduAcademyService {
@Autowired
private EduAcademyService academyService;
@Autowired
private EduClasssService classsService;
@Autowired
private EduMajorService majorService;
	@Override
	public boolean removeById1(Serializable id) {
	    Integer result = baseMapper.deleteById(id);
	    
	    return null != result && result > 0;
	}

	@Override
	public List<AcademyVo> findList() {
		List<EduAcademy> list = academyService.list(null);
		List<EduMajor> list2 = majorService.list(null);
		List<EduClasss> list3 = classsService.list(null);
		ArrayList<AcademyVo> AcaarrayList = new ArrayList<AcademyVo>();
		for(EduAcademy i:list) {
			AcademyVo academyVo = new AcademyVo();
			BeanUtils.copyProperties(i, academyVo);
			AcaarrayList.add(academyVo);
			ArrayList<MajorVo> majarrayList = new ArrayList<MajorVo>();
			for(EduMajor j:list2) {
				MajorVo majorVo = new MajorVo();
				if(i.getId().equals(j.getAcademyId())) {
					BeanUtils.copyProperties(j, majorVo);
					majarrayList.add(majorVo);
				}
				ArrayList<ClasssVo> claarrayList = new ArrayList<ClasssVo>();
				for(EduClasss k:list3) {
					ClasssVo classsVo = new ClasssVo();
					if(j.getId().equals(k.getMajorId())) {
						BeanUtils.copyProperties(k, classsVo);
						claarrayList.add(classsVo);
					}
				}
				majorVo.setChildren(claarrayList);
			}
			academyVo.setChildren(majarrayList);
		
		}
		return AcaarrayList;
	}
}
